<!-- 模板 -->
<template>
    <div class="app__body" :class="{'app__body--show': isRunAnimation}" v-if="isShowPage">
        <div class="app__header">
            <label>这次没中，下次再秒</label>
        </div>
        <div class="main">
            <div class="main__banner" v-if="activityInfo.next">
                <div class="main__banner__inner">
                    <span class="main__banner__nexticon">下期预告</span>
                    <img :src="aliyun + activityInfo.next.carImgs[0]">
                    <div class="main__banner__info">
                        <div class="main__banner__info__detail">
                            <label><em>￥</em>{{ activityInfo.next.limitPrice }}<span>/周末</span></label>
                            <p>{{ activityInfo.next.name }}</p>
                        </div>
                        <a href="javascript:;" class="app-btn app-btn--setting" @click="messageTip">
                            <i class="aui-icon aui-icon--countdown"></i>
                            下次提醒我哦！
                        </a> 
                    </div>
                </div>
            </div>
            <div class="main__winnerlist">
                <a href="javascript:;" @click="winnerList" class="main__winnerlist__btn">查看获奖名单 >></a>
            </div>
            <div class="app-carrecommand" v-if="carList && carList.length > 0">
                <div class="app-carrecommand-inner">
                    <h2>有急用？我们为你准备了以下特价车辆</h2>
                    <div class="app-carrecommand-carlist" id="A_CarRecommand">
                        <ul class="clearfix">
                            <template v-for="cars in carList">
                                <li class="car-items">
                                    <template v-for="car in cars">
                                        <div class="car-item">
                                            <div class="car-img">
                                                <img :src="aliyun + car.carPic">
                                            </div>
                                            <div class="car-info">
                                                <h2 class="aui-ellipsis-1">{{ car.carName }}</h2>
                                                <h3><i>￥</i>{{ car.dayPrice }}<i>/天</i> <em>{{ car.plateNum.substr(0, 2) }}<span>、</span>{{ car.gearboxType == '1'? '手动': '自动' }}</em></h3>
                                                <a class="app-btn app-btn--zuche" :href="host + 'view/h5/zuche/html/details.html?source='+ userSubscribeInfo.channel +'&carNo=' + car.carNo +'&channel=hcxsq'">点击租用</a>
                                            </div>   
                                        </div>
                                    </template>
                                </li>
                            </template>
                        </ul>
                    </div>
                    <div class="app-carrecommand-indicator" v-if="carList.length > 1">
                        <span class="app-carrcommand-dot" v-for="(item, index) in carList" :class="{'app-carrecommand-dot-active': index == indicatorIndex}"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>


<!-- js -->
<script>
    import { DB } from '../config/db.js';
    import _ from 'lodash/array/';
    import Swipe from '../libs/swipe.js';
    import wxEvent from '../filter/wxconfig.js';

    export default{
        data(){
            return{
                isRunAnimation: 0,
                aliyun: DB.aliyundomain,
                host: DB.host,
                indicatorIndex: 0
            }
        },
        computed: {
            activityInfo(){
                return this.$store.state.ownPrizeInfo;
            },
            carList(){
                return  _.chunk(this.activityInfo.cars, 4);
            },
            userSubscribeInfo(){
                return this.$store.state.userSubscribeInfo;
            },
            // 显示页面  等store获取数据之后才能
            isShowPage(){
                return this.$store.state.currentActivityInfo.cityCode? true: false 
            }
        },
        methods: {
            messageTip(){
                wxEvent.tongjiEvents(this.$store, 'nexttip');
                if(this.$store.state.userSubscribeInfo.subscribe == 0){
                    this.$store.commit('showQRPop', true);
                    return;
                }
                return this.$http.post(DB.ip + 'activity/remind', {
                    openid: this.userSubscribeInfo.openid,
                    activityId: this.activityInfo.next.id,
                    channel: this.userSubscribeInfo.channel
                }).then((res) => {
                    if(res.data.resCode == '999999'){
                        this.$aui.toast.show(res.data.resMsg);
                    }else{  
                        this.$aui.toast.show({
                            duration: 3000,
                            type: 5
                        });
                    }
                }, (error) => {
                    this.$aui.toast.show('系统错误，错误代码：' + error.status)
                });
            },
            winnerList(){
                this.$router.push({name: 'rank', query: {
                        id: this.$route.query.id, 
                        channel: this.$store.state.userSubscribeInfo.channel, 
                        activityId: this.$store.state.userSubscribeInfo.activityId, 
                        bind: this.$store.state.userSubscribeInfo.bind, 
                        subscribe: this.$store.state.userSubscribeInfo.subscribe, 
                        unionid: this.$store.state.userSubscribeInfo.unionid, 
                        openid: this.$store.state.userSubscribeInfo.openid
                    }
                });
            },
            initStart(){
                // 没有获奖，并且是第一次进入，根据判断是否是新老用户
                if(this.activityInfo.hasWin == 0 && this.$route.params.isFirst == 1 && sessionStorage['hcxsq_end_firstenter'] != '1'){
                    sessionStorage['hcxsq_end_firstenter'] = '1';
                    if(this.$store.state.isNew === 0  || (!this.activityInfo.currentActivityId && !this.userSubscribeInfo.activityId) && (this.activityInfo.currentActivityId === this.userSubscribeInfo.activityId) && this.$store.state.userSubscribeInfo.bind == 1){
                        this.$store.commit('showQuanPop', true);
                    }else{
                        this.$store.commit('showAtbiPop', true);
                    }
                }

                //滚动回调事件
                this.$nextTick(()=> {
                    if(this.carList.length <= 1){
                        return;
                    }
                    new Swipe(document.getElementById("A_CarRecommand"), {
                        continuous: false,
                        transitionEnd: (index, elem)=> {
                            this.indicatorIndex = index;
                        }
                    });
                });
            },
            refreshPage(){
                this.$aui.loading.show({
                    type: 1
                });

                return this.$http.post(DB.ip + 'activity/join', {
                    openid: this.$store.state.userSubscribeInfo.openid,
                    activityId: this.$store.state.currentActivityInfo.current.id,
                    channel: this.$store.state.userSubscribeInfo.channel
                }).then((res) => {
                    this.$aui.loading.hide();  
                    if(res.data.resCode == '000000' || res.data.resCode == '111116' || res.data.resCode == '111117' || res.data.resCode == '111118'){
                        res.data.data.currentActivityId = this.$store.state.currentActivityInfo.current.id;
                        this.$store.commit('setOwnPrizeInfo', res.data.data);
                    }else{
                        this.$aui.toast.show(res.data.resMsg);
                    }

                    this.initStart();
                }, (error) => {
                    this.$aui.loading.hide(); 
                    this.$aui.toast.show('系统错误，错误码：' + error.status);
                });
            }
        },
        watch: {
            isShowPage(){
                this.refreshPage();
            }
        },
        mounted(){
            this.$aui.loading.hide();
            
            setTimeout(() => {
                this.isRunAnimation = 1;
            }, 10);

            if(this.$store.state.currentActivityInfo && this.$store.state.currentActivityInfo.cityCode){
                this.initStart();
            }
        }
    }
</script>

<!-- scss -->
<style scoped lang="scss">
    @import "../styles/common/config.scss";
    .app__body{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 9;
        overflow: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch; 
        background-color: #114384;
        color: #fff;

        &--show{
            .app__header{
                transform: perspective(400px) rotateX(0);
            }
        }
    }

    .app__header{
        width: 100%;
        height: 1.2rem;
        background-color: #6989b0;
        border-radius: 0 0 22px 22px;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 9;
        transform: perspective(400px) rotateX(-90deg);
        transition: transform 0.8s cubic-bezier(.165,.84,.44,1);
        transform-origin: 50% 0;
        font-size: 0.40rem;
        text-align: center;
        line-height: 1.2rem;
        font-weight: bold;
        @include flexbox;
        @include flexCenterHori;
        @include flexCenterVeri;
        label{
            padding: 0 0.2rem;
        }
        &:before{
            width: 1.5rem;
            height: 0.04rem;
            content: "";
            background: url("../assets/images/line_rule_shadow.png") 0 0 no-repeat;
            background-size: 1.5rem 0.04rem;
        }
        &:after{
            width: 1.5rem;
            height: 0.04rem;
            content: "";
            background: url("../assets/images/line_rule_shadow.png") 100% 0 no-repeat;
            background-size: 1.5rem 0.04rem;
            transform: rotate(180deg);
            margin-top: 2px;
        }
    }

    .main{
        position: relative;
        color: #a8a8a8;
        @at-root &__banner{
            position: relative;
            overflow: hidden;
            width: 100%;
            &__inner{
                width: 100%;
                // position: absolute;
                &:before{
                    width: 100%;
                    height: 3.0rem;
                    content: "";
                    position: absolute;
                    bottom: 0;
                    background: url("../assets/images/end_banner_shadow.png") 50% 100% no-repeat;
                    background-size: 100%;
                    pointer-events: none;
                    z-index: 2;
                }
            }
            &__nexticon{
                min-width: 1.4rem;
                height: 0.6rem;
                line-height: 0.6rem;
                padding: 0 0.2rem;
                display: block;
                text-align: center;
                color: #fff;
                position: absolute;
                top: 1.5rem;
                left: 0.5rem;
                background: -webkit-gradient(linear, left top, right top, color-stop(0%,#f5c34c), color-stop(100%,#ff725f));
                border-radius: 0.3rem 0;
                font-size: 0.38rem;
                z-index: 3;
            }

            >img{
                display: block;
                width: 100%;
            }
            @at-root &__info{
                position: absolute;
                bottom: 0;
                width: 100%;
                color: #fff;
                z-index: 3;

                @at-root &__detail{
                    width: 100%;
                    @include flexbox;
                    @include flexCenterHori;
                    padding: 0.2rem 0;
                    label{
                        color: #ffca4c;
                        font-size: 0.65rem;
                        position: relative;
                        font-weight: bold;
                        padding-left: 0.35rem;
                        padding-right: 0.2rem;
                        >em{
                            font-size: 0.35rem;
                            position: absolute;
                            top: 0.05rem;
                            left: 0;
                            font-weight: bold;
                            text-indent: -1px;
                        }
                        span{
                            font-size: 0.24rem;
                            color: #fff;
                            padding: 0 0.05rem;
                        }

                        &:after{
                            position: absolute;
                            width: 1px;
                            height: 80%;
                            top: 10%;
                            right: 0;
                            content: "";
                            background-color: #fff;
                        }
                    }
                    p{
                        font-size: 0.38rem;
                        padding: 0 0.2rem;
                        line-height: 0.8rem;
                        font-weight: bold;
                    }
                }
            }
        }
    }

    .app-btn{
        position: relative;
        display: block;
        width: 100%;
        text-align: center;
        text-decoration: none;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        cursor: pointer;
        border-width: 0;
        -webkit-appearance: none; 
        outline: 0;
        color: #fff;
        &--booking{
            padding: 0.35rem 1.0rem;
        }
        &--setting{
            margin: 0 auto;
            border-radius: 5px;
            width: 75%;
            height: 0.8rem;
            line-height: 0.8rem;
            background: -webkit-gradient(linear, left top, right top, color-stop(0%,#f5c34c), color-stop(100%,#ff725f));
            font-size: 0.3rem;
            .aui-icon--countdown{
               font-size: 0.36rem;
            }
            &:active{
                background: #ff725f;
            }
        }
        &--zuche{
            width: 2.7rem;
            height: 0.5rem;
            border-radius: 0.25rem;
            font-size: 0.26rem;
            line-height: 0.5rem;
            margin: 0 auto;
            background: -webkit-gradient(linear, left top, right top, color-stop(0%,#f5c34c), color-stop(100%,#ff725f));
            &:active{
                background: #ff725f;
            }
        }
    }

    .main__winnerlist{
        width: 100%;
        padding-bottom: 0.35rem;
        color: #ffca4c;
        font-size: 0.24rem;
        background: url(path("line_shadow.png")) 50% 100% no-repeat;
        background-size: 270px 2px;
        @include flexbox;
        @include flexCenterHori;
        margin-top: 0.3rem;
        .main__winnerlist__btn{
            color: #ffca4c;
            font-size: 0.26rem;
            &:active{
                color: #f4c34e;
            }
        }
    }

    .main__cars{
        overflow: hidden;
        padding: 0 0.3rem 0.8rem 0.3rem;
        position: relative;
        color: #ffffff;
        >h2{
            line-height: 1.0rem;
            text-align: center;
            font-size: 0.3rem;
        }
        @at-root &__list{
            
        }
    }

    .app-carrecommand{
        position: relative;
        width: 100%;
        z-index: 9;
        .app-carrecommand-inner{
            position: relative;
            padding-bottom: 0.8rem;
            transform: translateZ(0);
            >h2{
                width: 100%;
                color: #fff;
                text-align: center;
                font-size: 0.3rem;
                line-height: 1rem;
            }
            @at-root .app-carrecommand-carlist{
                overflow: hidden;
                width: 100%;
                position: relative;
                transform: translateZ(0);
                >ul{ 
                    max-height: 9rem;
                    overflow: hidden;
                    position: relative;
                    @include flexbox;
                }
                @at-root .car-items{
                    width: 100%;
                    position: relative;
                    overflow: hidden;
                    padding: 0 0.4rem;
                    @include flexAuto;
                    // flex: 0 0 100%;
                    @at-root .car-item{
                        width: 100%;
                        background: #ffffff;
                        @include flexbox;
                        height: 1.8rem;
                        border-radius: 0 20px 0 20px;
                        overflow: hidden;
                        margin-top: 0.24rem;
                        &:first-child{
                            margin-top: 0;
                        }
                        @at-root .car-img{
                            width: 2.4rem;
                            height: 1.8rem;
                            >img{
                                display: block;
                                max-width: 100%;
                                width: 100%;
                                height: 100%;
                            }
                            border-radius: 0 0 0 20px;
                            overflow: hidden;
                        }
                        @at-root .car-info{
                            @include flexAuto;
                            padding-top: 0.1rem;
                            background: url(../assets/images/wave_lintener_bg.png) 50% 100% no-repeat; 
                            background-size: 100% auto;
                            >h2{
                                line-height: 0.5rem;
                                color: #000;
                                font-size: 0.3rem;
                                font-weight: bold;
                                text-align: center;
                                padding: 0 0.1rem;
                            }
                            >h3{
                                text-align: center;
                                color: #ff725f;
                                font-size: 0.34rem;
                                font-weight: bold;
                                line-height: 0.6rem;
                                >i{
                                    display: inline-block;
                                    font-size: 0.24rem;
                                }
                                em{
                                    color: #8f8f8f;
                                    font-size: 0.24rem;
                                }
                                >span{
                                    padding: 0 2px;
                                }
                            }
                        }
                    }
                }

                @at-root .app-carrecommand-indicator{
                    width: 100%;
                    @include flexbox;
                    height: 0.8rem;
                    @include flexCenterHori;
                    @include flexCenterVeri;
                    position:absolute;
                    bottom: 0;
                    @at-root .app-carrcommand-dot{
                        width: 0.2rem;
                        height: 0.2rem;
                        margin: 0 0.1rem;
                        border-radius: 50%;
                        border: solid 1px #fff;
                        display: block;
                        transition: all 0.3s ease-out;
                        &.app-carrecommand-dot-active{
                            background: #fff;
                            border: none;
                        }
                    }
                }
            }
        }
    }
</style>
